package com.yjc.hire.auth.controller;


import com.yjc.hire.grace.result.GraceJSONResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;
import java.util.concurrent.TimeUnit;

import static com.yjc.hire.base.BaseInfoProperties.SAAS_PLATFORM_LOGIN_TOKEN;
import static com.yjc.hire.base.BaseInfoProperties.SAAS_PLATFORM_LOGIN_TOKEN_READ;

@RestController
@RequestMapping("saas")
@Slf4j
public class SaasPassPortController {

    @Autowired
    private StringRedisTemplate redisTemplate;

    @PostMapping("getQRToken")
    public GraceJSONResult getQRToken(){
        String qrToken = UUID.randomUUID().toString();
        redisTemplate.opsForValue().set(SAAS_PLATFORM_LOGIN_TOKEN + ":" + qrToken,qrToken,5 * 60, TimeUnit.SECONDS);
        redisTemplate.opsForValue().set(SAAS_PLATFORM_LOGIN_TOKEN_READ + ":" + qrToken,"0",5 * 60,TimeUnit.SECONDS);
        return GraceJSONResult.ok(qrToken);
    }
}
